//
//  AMBaseRequestEntity.m
//  WeiDu_1_0
//
//  Created by foguo-mac-1 on 01/07/16.
//  Copyright (c) 2016 WeiDu Energy Tech. All rights reserved.
//

#import "HOBaseRequestEntity.h"
#import "HOConstants.h"

@implementation HOBaseRequestEntity
@synthesize params;
@synthesize priority;
@synthesize status;
@synthesize progress;
@synthesize action;
@synthesize moduleLiseners;
@synthesize sequence;
@synthesize requestTimes;
- (instancetype)init
{
    if(self = [super init])
    {
        params = [[NSMutableDictionary alloc] init];
        priority = HO_REQUEST_PRIORITY_MIDDLE;
        moduleLiseners = [[NSMutableArray alloc] init];
		self.progress = 0;
		
    }
    return self;
}
- (void)addParam:(id)anObject forKey:(id<NSCopying>)aKey
{
    if(params == nil)
        return;
    [params setObject:anObject forKey:aKey];
}
- (id)paramForKey:(id<NSCopying>)aKey
{
    return [params objectForKey:aKey];
}
- (void)addModule:(HO_MODULE_TYPE)type
{
    [moduleLiseners addObject:[NSNumber numberWithInt:type]];
}

- (NSString *)getFullURL
{
    return kServerPath;
}


- (NSString *)getMethod
{
	NSString *method = [params objectForKey:kHO_FIELD_Method];
	if(method)
		return method;
    return @"POST";
}

- (void)cleanup
{
    self.action = nil;
    [self.params removeAllObjects];
    priority = HO_REQUEST_PRIORITY_MIDDLE;
    status = HO_REQUEST_STATUS_UNDO;
    [moduleLiseners removeAllObjects];
}

- (void)dealloc
{
    [self cleanup];
    [params release];
    params = nil;
    
    [moduleLiseners release];
    moduleLiseners = nil;
	self.httpRequest = nil;
    [super dealloc];
}

- (void)cancelRequest
{
	[self.httpRequest cancelRequest];
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"AMBaseReqeustEntity - action:%@ pointer:%@", action, [super description]];
}

@end
